<!--
  Copyright © 2015 Cask Data, Inc.

  Licensed under the Apache License, Version 2.0 (the "License"); you may not
  use this file except in compliance with the License. You may obtain a copy of
  the License at

  http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  License for the specific language governing permissions and limitations under
  the License.
-->

<my-breadcrumbs></my-breadcrumbs>

<br/>

<div class="row">
  <div class="col-xs-7 col-md-6 text-left">
    <h2> All Applications </h2>
  </div>
  <div class="col-xs-5 col-md-2 h2 text-right">
    <div class="btn-group dropdown-right" uib-dropdown>
      <button type="button"
              class="btn btn-default dropdown-toggle"
              uib-dropdown-toggle=""
              aria-haspopup="true"
              aria-expanded="false">
        Add Application <span class="caret"></span>
      </button>
      <ul class="dropdown-menu dropdown-menu-right" role="menu">
        <li role="presentation">
          <my-file-select dropdown="true"
                          data-button-label="Custom App"
                          data-button-icon="__"
                          on-file-select="ListController.onFileSelected($files)">
          </my-file-select>
        </li>
        <li>
          <a ui-sref="hydratorplusplus.create({ namespace: $stateParams.namespace })"  class="clearfix">
            <span class="pull-left">{{ListController.GLOBALS.en.hydrator.appLabel}}</span>
          </a>
        </li>
      </ul>
    </div>
  </div>
  <div class="col-md-4 h2 text-right">
    <div class="input-group pull-right">
      <input type="text" class="form-control" ng-model="ListController.searchText" placeholder="search...">
      <div class="input-group-addon">
        <i class="fa fa-search"></i>
      </div>
    </div>
  </div>
</div>
<div ng-if="ListController.apps.length === 0">
  <div class="well well-lg text-center">
    <h3>You haven't deployed any applications</h3>
  </div>
</div>

<div class="table-responsive"  ng-if="ListController.apps.length > 0">
  <table class="table table-curved" cask-sortable>
    <thead>
      <tr ng-class="{'sort-enabled': ListController.apps.length>0}">
        <th data-predicate="name"> Name </th>
        <th data-predicate="type"> Type </th>
        <th data-predicate="version"> Version </th>
        <th data-predicate="description"> Description </th>
      </tr>
    </thead>
    <tbody>
      <tr ng-repeat="app in ListController.filtered = (ListController.apps | filter: ListController.searchText ) | myPaginate:ListController.currentPage | orderBy:sortable.predicate:sortable.reverse">
        <td >
          <a ui-sref="apps.detail.overview.programs({ appId: app.name })"
              ng-if="ListController.myHydratorFactory.isCustomApp(app.artifact.name)"
              ng-click="MyOrderings.appClicked(app.name)">
            <strong uib-tooltip="{{app.name}}"
                    tooltip-enable="app.name.length > 35"
                    tooltip-append-to-body="true">
              {{ ::app.name | myEllipsis:35 }}
            </strong>
          </a>
          <a ui-sref="apps.detail.overview.status({ appId: app.name })"
              ng-if="ListController.myHydratorFactory.isETLApp(app.artifact.name)"
              ng-click="MyOrderings.appClicked(app.name)">
            <strong uib-tooltip="{{app.name}}"
                    tooltip-enable="app.name.length > 35"
                    tooltip-append-to-body="true">
              {{ ::app.name | myEllipsis:35 }}
            </strong>
          </a>
        </td>
        <td>
          <span ng-if="ListController.myHydratorFactory.isCustomApp(app.artifact.name)">
            <span class="icon-fist"></span>
            <span>App</span>
          </span>
          <span ng-if="ListController.myHydratorFactory.isETLApp(app.artifact.name)">
            <span class="icon-{{ ListController.GLOBALS.iconArtifact[app.artifact.name] }}"></span>
            <span>{{ ListController.GLOBALS.artifactConvert[app.artifact.name] }}</span>
          </span>
        </td>
        <td>{{ ::app.version }}</td>
        <td>
          <span>{{ ::app.description }}</span>
        </td>
      </tr>
    </tbody>
  </table>
</div>

<div class="text-center" ng-if="ListController.filtered.length > 10">
  <uib-pagination total-items="ListController.filtered.length" ng-model="ListController.currentPage"></uib-pagination>
</div>
